package trading.strategy;

import trading.Parameters;
import trading.data.IDataType;
import trading.data.IStockTickDataCollection;
import trading.formulas.MACD;

public class MACDStrategy extends MACD implements ITradingStrategy {

	private MACDStrategy(){};
	
	public static MACDStrategy getMACDStrategy()
	{
		return new MACDStrategy();
	}
	
	@Override
	public boolean shouldBuy(IStockTickDataCollection dataCollection, int index) {
		if(index == 0)
		{
			return Boolean.FALSE;
		}
		float diff = super.getDIF(dataCollection, index, IDataType.CLOSE_NAME);
		float lastdiff = super.getDIF(dataCollection, index - 1, IDataType.CLOSE_NAME);
		float macd = super.getMACD(dataCollection, index, IDataType.CLOSE_NAME);
		
		return (diff > lastdiff && macd > 0);
	}

	@Override
	public boolean shouldSale(IStockTickDataCollection dataCollection, int index) {
		if(index == 0)
		{
			return Boolean.FALSE;
		}
		float diff = super.getDIF(dataCollection, index, IDataType.CLOSE_NAME);
		float lastdiff = super.getDIF(dataCollection, index - 1, IDataType.CLOSE_NAME);
		return diff < lastdiff;
	}

	@Override
	public Parameters getParameters() {
		return super.getParameters();
	}

//	@Override
//	public Object getValue(String name,
//			IStockTickDataCollection dataCollection, int index)
//			throws TradingFunctionException {
//		if(name.equalsIgnoreCase(BUY))
//		{
//			return shouldBuy(dataCollection, index);
//		}
//		else if(name.equalsIgnoreCase(SALE))
//		{
//			return shouldSale(dataCollection, index);
//		}
//		else
//		{
//			return super.getValue(name, dataCollection, index);
//		}
//	}
	

}
